"""
    字段拼接成模型类中的to_dict()方法中的字符串
"""

# 定义文件路径
input_file_path = 'field.txt'
output_file_path = 'output.txt'

try:
    # 以读模式打开文件
    with open(input_file_path, 'r', encoding='utf-8') as file:
        lines = file.readlines()  # 读取所有行

    # 处理每一行，在每行末尾添加“+”
    # modified_lines = [line.strip() + '+' + '\n' for line in lines]
    # 处理每一行
    modified_lines = ["'" + line.strip() + "': self." + line.strip() + ',\n' for line in lines]

    # 以写模式打开输出文件
    with open(output_file_path, 'w', encoding='utf-8') as file:
        file.writelines(modified_lines)  # 写入修改后的所有行

    print("文件处理完成！")
except FileNotFoundError:
    print(f"错误：找不到文件 {input_file_path}")
except Exception as e:
    print(f"发生错误：{e}")
